import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Form';
import { useI18n } from '/@/hooks/web/useI18n';

import { getCodeList } from '/@/api/demo/system';

const { t } = useI18n();

export function getFigureDocSettingsColumns(): BasicColumn[] {
  return [
    {
      title: t('routes.demo.FigureDocSettings.figureDocTypeId'),
      dataIndex: 'id',
      width: 200,
      fixed: 'left',
    },
    {
      title: t('routes.demo.FigureDocSettings.figureDocTypeName'),
      dataIndex: 'name',
      width: 200,
    },
    {
      title: t('routes.demo.FigureDocSettings.codingSystemAssociation'),
      dataIndex: 'counterID',
      width: 200,
    },
  ];
}

export function getDocSettingForm(isUpdate): FormSchema[] {
  return [
    {
      field: 'oId',
      component: 'Input',
      required: true,
      label: t('routes.demo.FigureDocSettings.figureDocTypeId'),
      componentProps: {
        placeholder: t('routes.demo.FigureDocSettings.figureDocTypeIdPlaceholder'),
      },
      dynamicDisabled: () => {
        return isUpdate.value;
      },
    },
    {
      field: 'name',
      component: 'Input',
      label: t('routes.demo.FigureDocSettings.figureDocTypeName'),
      defaultValue: '',
      componentProps: {
        placeholder: t('routes.demo.FigureDocSettings.figureDocTypeNamePlaceholder'),
      },
    },
    {
      field: 'counterID',
      component: 'ApiSelect',
      label: t('routes.demo.FigureDocSettings.codingSystemAssociation'),
      componentProps: {
        api: () =>
          getCodeList().then((res) => {
            const newArr = res.map((item) => {
              return {
                ...item,
                remark: item.counterID + item.remark,
              };
            });
            return newArr;
          }),
        placeholder: t('routes.demo.FigureDocSettings.codingSystemAssociationPlaceholder'),
        labelField: 'remark',
        valueField: 'counterID',
      },
    },
    {
      field: 'createSoft',
      component: 'Input',
      label: t('routes.demo.FigureDocSettings.producingSoftware'),
      defaultValue: '',
      componentProps: {
        placeholder: t('routes.demo.FigureDocSettings.producingSoftwarePlaceholder'),
      },
    },
    {
      field: 'check1',
      component: 'Checkbox',
      defaultValue: false,
      label: t('routes.demo.FigureDocSettings.partAttachment'),
      colProps: {
        span: 6,
      },
      itemProps: {
        labelCol: {
          span: 16,
        },
        wrapperCol: {
          span: 6,
        },
      },
    },
    {
      field: 'check2',
      component: 'Checkbox',
      defaultValue: false,
      label: t('routes.demo.FigureDocSettings.threeDimensionalData'),
      colProps: {
        span: 6,
      },
      itemProps: {
        labelCol: {
          span: 16,
        },
        wrapperCol: {
          span: 6,
        },
      },
    },
    {
      field: 'check3',
      component: 'Checkbox',
      defaultValue: false,
      label: t('routes.demo.FigureDocSettings.oneFigureManyParts'),
      colProps: {
        span: 6,
      },
      itemProps: {
        labelCol: {
          span: 16,
        },
        wrapperCol: {
          span: 6,
        },
      },
      componentProps: {
        // disabled: true,
      },
    },
    {
      field: 'check4',
      component: 'Checkbox',
      defaultValue: false,
      label: t('routes.demo.FigureDocSettings.generateDrawingFrame'),
      colProps: {
        span: 6,
      },
      itemProps: {
        labelCol: {
          span: 16,
        },
        wrapperCol: {
          span: 6,
        },
      },
      componentProps: {
        // disabled: true,
      },
    },
    {
      field: 'check5',
      component: 'Checkbox',
      defaultValue: false,
      label: t('routes.demo.FigureDocSettings.craftFile'),
      colProps: {
        span: 6,
      },
      itemProps: {
        labelCol: {
          span: 16,
        },
        wrapperCol: {
          span: 6,
        },
      },
    },
    {
      field: 'check6',
      component: 'Checkbox',
      defaultValue: false,
      label: t('routes.demo.FigureDocSettings.browsePdfFile'),
      colProps: {
        span: 6,
      },
      itemProps: {
        labelCol: {
          span: 16,
        },
        wrapperCol: {
          span: 6,
        },
      },
    },
    {
      field: 'template',
      component: 'Divider',
      label: '图文档id',
      defaultValue: 'none',
      show: false,
    },
    {
      field: 'Divider',
      component: 'Divider',
      label: t('routes.demo.FigureDocSettings.sourceFileStorageWay'),
    },
    {
      field: 'sourceFileStorageWay',
      component: 'RadioGroup',
      label: '',
      defaultValue: '0',
      componentProps: {
        options: [
          { label: t('routes.demo.FigureDocSettings.databaseStorage'), value: '0' },
          { label: t('routes.demo.FigureDocSettings.ftpStorage'), value: '1' },
        ],
      },
      dynamicDisabled: () => {
        return isUpdate.value;
      },
    },
    {
      field: 'datavault',
      component: 'Input',
      label: t('routes.demo.FigureDocSettings.ftpStorage'),
      defaultValue: '',
      componentProps: {
        placeholder: t('routes.demo.FigureDocSettings.ftpStoragePlaceholder'),
      },
      dynamicDisabled: (params) => {
        return isUpdate.value || params.values.sourceFileStorageWay === '0' ? true : false;
      },
    },
  ];
}

export function getClassAttrModalColumns(): BasicColumn[] {
  return [
    {
      title: t('routes.demo.partSetting.propertyId'),
      dataIndex: 'prop',
      width: 150,
      fixed: 'left',
    },
    {
      title: t('routes.demo.partSetting.propertyName'),
      dataIndex: 'name',
      align: 'center',
      width: 120,
    },
    {
      title: t('routes.demo.partSetting.dataType'),
      dataIndex: 'dataType',
      width: 120,
    },
    {
      title: t('routes.demo.partSetting.length'),
      dataIndex: 'length',
      width: 120,
    },
    {
      title: t('routes.demo.partSetting.control'),
      dataIndex: 'attr',
      width: 120,
      slots: { customRender: 'attr' },
    },
    {
      title: t('routes.demo.partSetting.order'),
      dataIndex: 'dispIndex',
      width: 120,
    },
    {
      title: t('routes.demo.partSetting.optionalValue'),
      dataIndex: 'defaultValue',
      width: 120,
    },
    {
      title: t('routes.demo.partSetting.allowEmpty'),
      dataIndex: 'pdmnull',
      width: 120,
      slots: { customRender: 'pdmnull' },
    },
    {
      title: t('routes.demo.partSetting.isSensitiveProperty'),
      dataIndex: 'isOnly',
      width: 120,
      slots: { customRender: 'isOnly' },
    },
    {
      title: t('routes.demo.partSetting.isDefaultProperty'),
      dataIndex: 'canChange',
      width: 120,
      slots: { customRender: 'canChange' },
    },
    // {
    //   title: t('routes.demo.partSetting.hasCodingSystem'),
    //   dataIndex: 'docTypeId',
    //   width: 120,
    // },
  ];
}

export function getTitleExtractColumns(docSysList): BasicColumn[] {
  return [
    {
      title: t('routes.demo.FigureDocSettings.userName'),
      dataIndex: 'userName',
      width: 100,
      fixed: 'left',
    },
    {
      title: t('routes.demo.FigureDocSettings.systemNameFigure'),
      dataIndex: 'docSystemName',
      width: 150,
      editComponent: 'Select',
      editable: true,
      editRow: true,
      editComponentProps: {
        options: docSysList.value,
      },
    },
    {
      title: t('routes.demo.FigureDocSettings.systemNamePart'),
      dataIndex: 'partSystemName',
      width: 150,
    },
  ];
}

export function getDetailExtractColumns(): BasicColumn[] {
  return [
    {
      title: t('routes.demo.FigureDocSettings.userName'),
      dataIndex: 'userName',
      width: 100,
      fixed: 'left',
    },
    {
      title: t('routes.demo.FigureDocSettings.systemName'),
      dataIndex: 'systemName',
      width: 150,
      editComponent: 'Select',
      editRow: true,
      editComponentProps: {
        options: [
          { label: 'facebook', value: 'facebook' },
          { label: 'twitter', value: 'twitter' },
        ],
      },
    },
  ];
}
